﻿// -------------------------------------------------------------------------
//    @FileName         :    NFSnsRoleDetail.h
//    @Author           :    gaoyi
//    @Date             :    2025-03-26
//    @Email			:    445267987@qq.com
//    @Module           :    NFSnsRoleDetail
//
// -------------------------------------------------------------------------

#pragma once

#include "NFLogicCommon/NFLogicShmTypeDefines.h"
#include <NFComm/NFObjCommon/NFISaveDb.h>
#include <NFComm/NFObjCommon/NFObjPtr.h>
#include <NFLogicCommon/NFCacheStatus.h>
#include <NFSnsServer/NFSnsCommon/NFSnsRoleSimple.h>



class NFSnsDetailPart;

class NFSnsRoleDetail : public NF_OBJECT_TEMPLATE_MACRO(NFSnsRoleDetail, EOT_SNS_ROLE_DETAIL, NFCacheDataWithSaveDb, public NFCacheStatus)
public:
    NFSnsRoleDetail();
    ~NFSnsRoleDetail() override;
    int CreateInit();
    int ResumeInit();
public:
    virtual int Init();
    virtual int UnInit();
public:
    bool IsNeedSave() const override;
    int SendTransToDb(int iReason) override;
    uint32_t GetAllSeq() const override;
    void ClearAllSeq() override;
    int GetCacheCreateTimeoutSec() const override { return std::numeric_limits<int>::max(); }
    int GetCacheExpireTimeSec() const override { return std::numeric_limits<int>::max(); }
public:
    int LoadFromDb(const proto_ff::tbSnsRoleDetail* pDbData);
    int SaveDb(proto_ff::tbSnsRoleDetail* pDbData);
public:
    // Set
    int SetCorpsId(uint64_t ullCorpsId);
    int SetRoleTax(int value);
    int SetName(const std::string& name);
    int SetLastLogoutTime(uint64_t time);
    int SetGuildInfo(uint64_t guildId, proto_ff::enGuildMemTitle title, const std::string& name);
    int ClearGuildInfo();

public:
    int Tick();
public:
    uint64_t GetCacheId() const override { return m_ullRoleId; };
    uint64_t StatusId() const override { return m_ullRoleId; }
    void SetRoleId(uint64_t roleId) { m_ullRoleId = roleId; }
    uint64_t GetRoleId() const { return m_ullRoleId; }
public:
    NFSnsRoleSimple* GetRoleSimple();
    template <typename PART>
    PART* GetPart()
    {
        return dynamic_cast<PART*>(GetPart(PART::GetStaticClassType() - EOT_SNS_DETAIL_PART_MIN_ID));
    }

    template <typename PART>
    const PART* GetPart() const
    {
        return dynamic_cast<const PART*>(GetPart(PART::GetStaticClassType() - EOT_SNS_DETAIL_PART_MIN_ID));
    }

    template <typename PART>
    PART* GetPart(uint32_t partType)
    {
        return dynamic_cast<PART*>(GetPart(partType));
    }

    template <typename PART>
    const PART* GetPart(uint32_t partType) const
    {
        return dynamic_cast<const PART*>(GetPart(partType));
    }

    NFSnsDetailPart* GetPart(uint32_t partType);

    const NFSnsDetailPart* GetPart(uint32_t partType) const;

    /**
     * @brief 创建Part
     * @param partType
     * @param dbData
     * @return
     */
    NFSnsDetailPart* CreatePart(uint32_t partType);

    /**
     * @brief 释放Part
     * @param pPart
     * @return
     */
    int RecylePart(NFSnsDetailPart* pPart) const;
public:
    /**
    * @brief 注册后的初始化
    * @return
    */
    virtual int OnRegister();

    /**
     * @brief 登陆入口
     * @return
     */
    virtual int OnLogin();

    /**
     * @brief 登出入口
     * @return
     */
    virtual int OnLogout();

    /**
     * @brief 掉线入口
     * @return
     */
    virtual int OnDisconnect();

    /**
     * @brief 重连入口
     * @return
     */
    virtual int OnReconnect();

    ////////////////////////////////// 每日零点 每周一零点 刷新接口 ///////////////////////////////////
    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    virtual int DailyZeroTick();

    /**
     * @brief 每日4/6点 刷新接口
     * @return
     */
    virtual int DailyOtherTick();

    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    virtual int WeekZeroTick();

    /**
     * @brief 每月刷新接口
     * @return
     */
    virtual int MonthZeroTick();
protected:
    uint64_t m_ullRoleId;
    NFShmVector<NFObjPtr<NFSnsDetailPart>, PART_SNS_DETAIL_MAX> m_pPart;
};
